<?php
session_start();
$loginId=$_SESSION['loginid'];
$name=$_SESSION['name'];
$userType=$_SESSION['user_type'];
$typeScheme=$_SESSION['type_scheme'];

include("config.php");
include("connection/connection.php");
$pipe_id=$_REQUEST['var'];
$code=$_REQUEST['code'];
$reference_id=$_REQUEST['referenceId'];
$qrSource="select * from tbl_dtls_q1_pipeline_ris_dis where id='$pipe_id'";
		$resSource=mysql_query($qrSource);
		//echo mysql_affected_rows();
		$rowSource=mysql_fetch_array($resSource);
		$loc_id=$rowSource['loc_id'];
		 if(isset($_REQUEST['submit'])){
  
  //print_r($_REQUEST); 
  if($_REQUEST['code']==1) 
  {
  	mysql_query("UPDATE tbl_dtls_q1_pipeline_ris_dis set rising_material= '$_REQUEST[material]' , rising_size = '$_REQUEST[size_mm]' , rising_length = '$_REQUEST[length]' WHERE id = '$_REQUEST[pipe_id]' ");
	
	$typeScheme=$_POST['typeScheme'];
		$frm=$_POST['frmId'];
	////////////////////////code for maintaining user history///////////////////
	if($typeScheme=="P&T" || $typeScheme=="TSS(P&T)")
	{
		$qryHistory="insert into tbl_new_user_history(user_id,form_id,action_id,ip_address,modify_date,user_type,user_name) values('$_POST[loginId]','$frm','15','$_SERVER[REMOTE_ADDR]',NOW(),'$_POST[userType]','$_POST[name]')";
	}
	if($typeScheme=="Piped")
	{
		$qryHistory="insert into tbl_new_user_history(user_id,form_id,action_id,ip_address,modify_date,user_type,user_name) values('$_POST[loginId]','$frm','41','$_SERVER[REMOTE_ADDR]',NOW(),'$_POST[userType]','$_POST[name]')";
	}
	if($typeScheme=="Sanitary Diggs")
	{
		$qryHistory="insert into tbl_new_user_history(user_id,form_id,action_id,ip_address,modify_date,user_type,user_name) values('$_POST[loginId]','$frm','67','$_SERVER[REMOTE_ADDR]',NOW(),'$_POST[userType]','$_POST[name]')";
	}
	
	
	mysql_query($qryHistory);
	///////////////////////////////
   }
	else 
	{
	mysql_query("UPDATE tbl_dtls_q1_pipeline_ris_dis set distri_material= '$_REQUEST[material]' , distri_size = '$_REQUEST[size_mm]' , distri_length = '$_REQUEST[length]' WHERE id = '$_REQUEST[pipe_id]' ");
	
	$typeScheme=$_POST['typeScheme'];
		$frm=$_POST['frmId'];
	////////////////////////code for maintaining user history///////////////////
	if($typeScheme=="P&T" || $typeScheme=="TSS(P&T)")
	{
		$qryHistory="insert into tbl_new_user_history(user_id,form_id,action_id,ip_address,modify_date,user_type,user_name) values('$_POST[loginId]','$frm','18','$_SERVER[REMOTE_ADDR]',NOW(),'$_POST[userType]','$_POST[name]')";
	}
	if($typeScheme=="Piped")
	{
		$qryHistory="insert into tbl_new_user_history(user_id,form_id,action_id,ip_address,modify_date,user_type,user_name) values('$_POST[loginId]','$frm','44','$_SERVER[REMOTE_ADDR]',NOW(),'$_POST[userType]','$_POST[name]')";
	}
	if($typeScheme=="Sanitary Diggs")
	{
		$qryHistory="insert into tbl_new_user_history(user_id,form_id,action_id,ip_address,modify_date,user_type,user_name) values('$_POST[loginId]','$frm','70','$_SERVER[REMOTE_ADDR]',NOW(),'$_POST[userType]','$_POST[name]')";
	}
	
	
	mysql_query($qryHistory);
	///////////////////////////////
	
   }
	
	
	
  header("Location: q1.php");
  }
?>
<script type="text/javascript" src="js/jquery.js"></script>
 <div class="section_format">
  <form action="pipeline_edit.php" method="post" name="sec5" id="sec5" onsubmit="return sec6_val();" >
  <input type="hidden" id="pipe_id" name="pipe_id" value="<?php echo $pipe_id; ?>"><input type="hidden" id="code" name="code" value="<?php echo $code; ?>">
  <input type="hidden" name="frmId" id="frmId" value="<?php echo $loc_id;?>" />
	  <input type="hidden" name="loginId" id="loginId" value="<?php echo $loginId;?>" />
	  <input type="hidden" name="name" id="name" value="<?php echo $name;?>" />
	  <input type="hidden" name="userType" id="userType" value="<?php echo $userType;?>" />
	  <input type="hidden" name="typeScheme" id="typeScheme" value="<?php echo $typeScheme;?>" />
  <div style="height:30px" align="center"><?php echo $reference_id;?></div>
  <table border="1">
    <tr>
      <td colspan="2">&nbsp;<b>Pipelines</b>&nbsp;</td>
      </tr>
   
	  
	  <tr>
      <td width="138">&nbsp;<b>Material</b></td>
      <td width="144">&nbsp;
	  <select name="material" id="material" >
	   <option value="0">Select</option>
	   <?php
	  foreach($material as $mat_data){
	  if($mat_data==$rowSource['rising_material'] && $code==1)
	  echo "<option value='".$mat_data."' selected>".$mat_data."</option>";
	  else if($mat_data==$rowSource['distri_material'] && $code==2)
	  echo "<option value='".$mat_data."' selected>".$mat_data."</option>";
	  else
	  echo "<option value='".$mat_data."'>".$mat_data."</option>";
	  }
	   ?>
  	    </select></td>
      </tr>
	   <tr>
      <td>&nbsp;<b>Size(mm)</b></td>
      <td>&nbsp;
	  <select name="size_mm" id="size_mm">
	  <option value="0">Select</option>
	  <?php
	  
	  foreach($size as $mm){
	  if($mm==$rowSource['rising_size'] && $code==1)
	  echo "<option value='".$mm."' selected>".$mm."</option>";
	  else if($mm==$rowSource['distri_size'] && $code==2)
	  echo "<option value='".$mm."' selected>".$mm."</option>";
	  else
	echo "<option value='".$mm."'>".$mm."</option>";	  }
	  
	  ?>
	  </select></td>
      </tr>
	  <tr>
	  <td>&nbsp;<b>Length (Km)</b></td>
	 <td>&nbsp;<input type="text" name="length" value="<?php echo $rowSource['rising_length'].$rowSource['distri_length'];  ?>"  onblur="int(this);" /></td>
	  </tr>

	  
	  <tr>
	    <td colspan="2" align="center"><input type="submit" value="EDIT PIPELINE" name="submit" style="font-size: 8pt; font-family: Verdana; border-style: solid; border-width: 1px; font-weight:bold; background:#666666; color:#FFFFFF; width:140px; height:30px" onClick="view_validate()"></td>
  </tr>
  </table>
    </form>
  </div>
  
